import {useState,useEffect} from 'react'
import {useLocation,useNavigate,Outlet} from 'react-router-dom'
import axios from 'axios'
// import http from '../../api/index.ts'
import { Tree} from 'antd';
import type { TreeDataNode, TreeProps } from 'antd';

const treeData:TreeDataNode[] = []

export default function Demo(){
    let [list,setlist] = useState([])
    let [dform,setdform] = useState()
    let [iform,setiform] = useState()
    let [mform,setmform] = useState()
    let [index,setindex] = useState([])
    

    let btndrug = async()=>{//添加西中药
        let {data:{code,msg}} = await axios.post('http://127.0.0.1:3000/why/drugadd',dform)
        if(code == 200){console.log(msg)}
    }
    let btninspect = async()=>{//添加检查检验项目
        let {data:{code,msg}} = await axios.post('http://127.0.0.1:3000/why/inspectadd',iform)
        if(code == 200){console.log(msg)}
    }
    let btnmachines = async()=>{//添加检查检验仪器
        let {data:{code,msg}} = await axios.post('http://127.0.0.1:3000/why/machinesadd',mform)
        if(code == 200){console.log(msg)}
    }
    let getshow = async(selectedKeys:any, e:{selected: boolean, selectedNodes:any, node:any, event:any})=>{
        // console.log(selectedKeys)
        // console.log(e.selectedNodes)
        // console.log(e.event)
        console.log(e.node)
        let {data:{lis}} = await axios.post('http://127.0.0.1:3000/why/getmachines',{id:e.node.id})
        setindex(lis)
        console.log(lis)
    }
    let getdata = async()=>{
        let {data:{lis}} = await axios.get('http://127.0.0.1:3000/why/sindex')
        setlist(lis)
    }

    useEffect(()=>{
        getdata()
    },[])

    return (
        <>
            <button onClick={()=>{btndrug()}}>添加药品</button>
            <button onClick={()=>{btninspect()}}>添加检查</button>
            <button onClick={()=>{btnmachines()}}>添加检查项目</button>
            <Tree
                defaultExpandAll={true}
                // defaultExpandedKeys={['1','2','3']}
                treeData={list}
                onSelect={getshow}
            />

        </>
    )
}